// 创建默认地址
// const BASE_URL = 'http://basketballManage.mooncode.cn'
const BASE_URL = 'http://localhost:8081'

export default ({
  url,
  method,
  data,
  contentType
}) => {
  // 获取token
  let token = uni.getStorageSync('token')

  // 返回promise对象
  return new Promise((resolve, reject) => {
    // 添加加载中提示
    uni.showLoading({
      title: '加载中'
    });

    uni.request({
      url: BASE_URL + url,
      method: method || 'get',
      data: data || {},
      header: {
        Authorization: token,
        'Content-type': contentType || 'application/json'
      },
      success: (res) => {
        resolve(res)
      },
      fail: (err) => {
        reject(res)
      },
      complete: () => {
        uni.hideLoading();
      }
    });
  })
}